package llvmir;

import llvmir.value.structure.Module;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class IrPrinter {
    private static IrPrinter instance;
    private BufferedWriter writer;
    private Module module = Module.getInstance();

    private IrPrinter() {
    }

    public static IrPrinter getInstance() {
        if (instance == null) {
            instance = new IrPrinter();
        }
        return instance;
    }

    public void initBuffer(String outputFile) throws IOException {
        writer = new BufferedWriter(new FileWriter(outputFile));
    }

    public void closeBuffer() throws IOException {
        writer.close();
    }

    public void showIr() throws IOException {
        writer.write(module.toString());
    }

}
